//
//  ViewController.m
//  自定义表情
//
//  Created by MyMac on 15/7/10.
//  Copyright (c) 2015年 MyMac. All rights reserved.
//

#import "ViewController.h"
#define EMOJI_CODE_TO_SYMBOL(x) ((((0x808080F0 | (x & 0x3F000) >> 4) | (x & 0xFC0) << 10) | (x & 0x1C0000) << 18) | (x & 0x3F) << 24);
@interface ViewController ()

@property (weak, nonatomic) IBOutlet UILabel *label;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self receiveImage];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//将数字转为

//定义的宏将转成UTF8，取出对应的表情符号：
//获取默认表情数组
- (NSArray *)defaultEmoticons {
    NSMutableArray *array = [NSMutableArray new];
    for (int i=0x1F600; i<=0x1F64F; i++) {
        if (i < 0x1F641 || i > 0x1F644) {
            int sym = EMOJI_CODE_TO_SYMBOL(i);
            NSString *emoT = [[NSString alloc] initWithBytes:&sym length:sizeof(sym) encoding:NSUTF8StringEncoding];
            [array addObject:emoT];
            NSLog(@"%@",emoT);
        }
    }
    return array;
}
//在将对应数组里的表情依次存放到UIButton里，贴出部分代码：

//获取数组
-(void)receiveImage
{
NSArray *arrEmotion = [self defaultEmoticons];
//将表情放到UIButton里
CGFloat W = 30;
CGFloat H = 30;
CGFloat X;
CGFloat Y;
for (int i = 0; i <arrEmotion.count; i ++) {
    X = 10 +(W+5) * (i%10);
    Y = 260 + (i/10)* (H +5);
    UIButton *biaoqing =[[UIButton alloc] init];
    biaoqing.backgroundColor = [UIColor redColor];
    biaoqing.frame = CGRectMake(X, Y, W, H);
    [self.view addSubview:biaoqing];
    NSString *Str = arrEmotion[i];
    [biaoqing setTitle:Str forState:UIControlStateNormal];
    biaoqing.tag = i;
    [biaoqing addTarget:self action:@selector(biaoqingClick:) forControlEvents:UIControlEventTouchUpInside];
}
}
-(void)biaoqingClick:(UIButton*)btn
{
    self.label.text=[NSString stringWithFormat:@"%@%@",self.label.text,btn.titleLabel.text];



}
@end
